package thread;

class Couter{
    private Object locker = new Object();

    private int count = 0;

    public void add(){
        synchronized (locker){
            count++;
        }
    }

    public int get(){
        return count;
    }
}
public class Demo18 {

    public static void main(String[] args) throws InterruptedException {
        Couter couter = new Couter();
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 5000; i++) {
                couter.add();
            }
        });

        Thread t2 = new Thread(()->{
            for (int i = 0; i < 5000; i++) {
                couter.add();
            }
        });
        t1.start();
        t2.start();

        Thread.sleep(1000);

        System.out.println(couter.get());


    }
}
